<%--
  Created by IntelliJ IDEA.
  User: KLHM
  Date: 2025/1/20
  Time: 下午2:03
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<html>
<head>
    <title>商品详情</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f4f4;
        }

        .container {
            width: 80%;
            margin: 50px auto;
            background-color: #e0f0ff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        .product-image {
            width: 100%;
            max-width: 600px;
            margin: 0 auto;
            border: 2px solid #ddd;
            border-radius: 10px;
            padding: 10px;
            text-align: center;
        }

        .product-info {
            margin-top: 20px;
        }

        .product-info label {
            display: inline-block;
            width: 150px;
            font-weight: bold;
        }

        .product-info span {
            display: inline-block;
            margin-left: 10px;
        }

        .buttons {
            margin-top: 20px;
            text-align: right;
        }

        .button {
            display: inline-block;
            padding: 10px 20px;
            margin-right: 10px;
            border: none;
            border-radius: 20px;
            background-color: #007bff;
            color: white;
            text-decoration: none;
            cursor: pointer;
        }

        .button:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="product-image">
        <img src="${product.url}" alt="商品图片" style="max-width: 100%; height: auto;">
    </div>


    <form id="form">
        <input type="hidden" name="id" value="${product.id}"/>
        <div class="product-info">
            <label>商品名字:</label>
            <span><input type="text" name="productName" value="${product.productName}" disabled/> </span><br>
            <label>商品描述:</label>
            <span>${product.description}</span><br>
            <label>商品库存:</label>
            <span>${product.stock}</span><br>
            <label>商品价格:</label>
            <span>${product.price}</span><br>
        </div>

        购买数量: <input type="number" name="stock"/>
        <div class="buttons">
            <a href="/product/list" class="button">返回</a>
        </div>
        <div class="buttons">
            <!-- 移除type="submit"并添加自定义的onclick事件 -->
            <input type="button" value="加入购物车" onclick="submitForm('/car/input')">
            <input type="button" value="购买" onclick="submitForm('/order/input')">
        </div>
    </form>

</div>
</body>


<script>
    function submitForm(action) {
        // 获取表单元素
        var form = document.getElementById('form');
        // 设置表单的action属性为传递的参数
        form.action = action;
        // 提交表单
        form.submit();
    }
</script>

</html>